import { session } from '../utils/jcore/storage'

/**
 * reducer 状态管理
 */
// 文章详情
export interface IFArticle {
  id: string
  pid: string
  isFile: number
  filePath: string
  fileName: string
  cover?: string
  children: IFArticle[]
}

export interface IFState {
  articleList: IFArticle[]
}

export interface IFAction {
  type: string
  articleList: IFArticle[]
}

const defaultState: IFState = {
  articleList: session.get('articleList') || []
}

export default (state: IFState = defaultState, action: IFAction) => {
  const { articleList } = action
  if (!articleList) {
    return state
  }
  return { articleList }
}
